/**
 * $Id: UserDAOHibernate.java,v 1.2 2005/05/13 10:55:01 phil Exp $
 *
 * Copyright Commerce, Inc. All Rights Reserved.
 */
package com.vip.example.dao.impl;

import java.util.HashMap;
import java.util.List;

import com.vip.framework.generic.GenericDaoImpl;
import com.vip.example.entity.User;

/**
 * 用户DAO的hibernate实现,如果GenericDao不够用,可以实现自己的Dao
 * 
 * @author sai
 *
 */
public class UserDAOImpl extends GenericDaoImpl<User>{

    public UserDAOImpl(User t) {
		super(t);
	}

	/**
     * 查询用户
     * 
     * @param con
     * @return
     */
    public List<User> search(HashMap<String,String> con, int page, int rowsPerPage) {
        StringBuffer sql = new StringBuffer();
        sql.append(" FROM User u WHERE 1=1 ");
        if (null != con.get("account") && !"".equals(con.get("account"))) {
            sql.append(" AND u.account like '%").append(con.get("account"))
                    .append("%'");
        }
        if (null != con.get("name") && !"".equals(con.get("name"))) {
            sql.append(" AND u.name like '%").append(con.get("name"))
                    .append("%'");
        }
        //TODO :改成按更新时间降序排列
        sql.append("ORDER BY u.id DESC");
        return (List<User>)pageListQuery(null,"u.id",sql.toString(),page,rowsPerPage);
    }
    
    public void testHQL(String sql){
        executeHQL(sql);    
    }
    
    public int testCountHQL(String sql,String field){
        return countHQL(sql,field);
    }

}